package com.hxb.notificationdemo.notification;

import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.launcher.ARouter;
import com.google.gson.Gson;

/**
 *  Notification广播接收者
 */
public class NotificationBroadcastReceiver extends BroadcastReceiver {

    public static final String TYPE = "type"; //这个type是为了Notification更新信息的，这个不明白的朋友可以去搜搜，很多


    @Override
    public void onReceive(Context context, Intent intent) {
        Log.e("Notification广播接收者","进入");
        String action = intent.getAction();
        int type = intent.getIntExtra(TYPE, -1);
        NotificationData data = new Gson().fromJson(intent.getStringExtra("Data"),NotificationData.class);
        if (type != -1) {
            NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.cancel(type);
        }
        switch (action){
            case NotificationAction.jump:
                //跳转事件
                ARouter.getInstance()
                        .build(data.getPath())
                        .navigation();
                break;
            case NotificationAction.click:
                //处理点击事件


                break;
            case NotificationAction.cancel:
                //处理滑动清除和点击删除事件




                break;
        }
    }


}
